import time
def read_from_file(filename):
    file = open(filename)
    data = file.readlines()
    data = list(map(int, data))
    return data

def bubble_sort(a):
    n = len(a)
    for i in range(n):
        flag = True
        for j in range(n - 1 - i):
            if a[j] > a[j + 1]:
                flag = False
                a[j], a[j + 1] = a[j + 1], a[j]
        if flag:
            return a

m1 = read_from_file('m1_sorted.txt')
m2 = read_from_file('m2_reverse.txt')
m3 = read_from_file('m3_shuffle.txt')

t_start_m1 = time.time()
bubble_sort(m1)
t_finish_m1 = time.time()
time_m1 = round((t_finish_m1 - t_start_m1) * 1000)
print(f"m1_sorted {time_m1} milliseconds")

t_start_m2 = time.time()
bubble_sort(m2)
t_finish_m2 = time.time()
time_m2 = round((t_finish_m2 - t_start_m2) * 1000)
print(f"m2_sorted {time_m2} milliseconds")

t_start_m3 = time.time()
bubble_sort(m3)
t_finish_m3 = time.time()
time_m3 = round((t_finish_m3 - t_start_m3) * 1000)
print(f"m3_sorted {time_m3} milliseconds")
